$(function () {
    load();
})
function fh() {
    localStorage.removeItem("MMADD(1)");
    location.href = "../../wen_zhi_yi/mManufactureAdd.html";
}

function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").text(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}

let duixiang = {};

function load() {
    let list = JSON.parse(localStorage.getItem("MMADD(1)"));
    let user = JSON.parse(localStorage.getItem("user"));
    let shuhe = 0;
    for (let i = 0; i < list.length; i++) {
        shuhe += list[i].amount;
        duixiang = {
            amount: shuhe,
            applyid: list[i].applyid,
            checker: list[i].checker,
            checksuggestion: list[i].checksuggestion,
            checktag: list[i].checktag,
            checktime: list[i].checktime,
            designer: list[i].designer,
            id: list[i].id,
            manufacturetag: list[i].manufacturetag,
            productdescribe: list[i].productdescribe,
            productid: list[i].productid,
            productname: list[i].productname,
            register: list[i].register,
            registertime: list[i].registertime,
            remark: list[i].remark,
            type: list[i].type
        };
    }
    let str = "     <tr>\n" +
        "                <th>工单制定人</th>\n" +
        "                <td><input type=\"text\" id=\"designer\"></td>\n" +
        "                <th>出库单编号集合</th>\n" +
        "                <td></td>\n" +
        "            </tr>\n" +
        "            <tr>\n" +
        "                <th>登记人</th>\n" +
        "                <td><input type=\"text\" id=\"rname\" value='" + user.rname + "'></td>\n" +
        "                <th>登记时间</th>\n" +
        "                <td><span id=\"date\"></span></td>\n" +
        "            </tr>\n" +
        "            <tr>\n" +
        "                <th>产品编号</th>\n" +
        "                <td><span id=\"productId\">"+duixiang.productid+"</span></td>\n" +
        "                <th>产品名称</th>\n" +
        "                <td><span id=\"productName\">"+duixiang.productname+"</span></td>\n" +
        "            </tr>\n" +
        "            <tr>\n" +
        "                <th>描述</th>\n" +
        "                <td><span id=\"productDescribe\">"+duixiang.productdescribe+"</span></td>\n" +
        "                <th>数量</th>\n" +
        "                <td><span id=\"amount\">"+duixiang.amount+"</span></td>\n" +
        "            </tr>\n" +
        "            <tr>\n" +
        "                <th>备注</th>\n" +
        "                <td><textarea style=\"width: 100%;\" id=\"remark\"></textarea></td>\n" +
        "                <th></th>\n" +
        "                <td></td>\n" +
        "            </tr>";
    $("#tableMFadd01").html(str);
    Time();
}

function yl() {
    $.post("/Mmanufacture.do/mManufactureWZY_tf",{id:duixiang.productid},function (sdata) {
        if (sdata!=1){
            $("#tishi").text("物料设计单、工序设计单、工序物料设计单都已设计完毕并通过审核！")
            $("#tishi").css("color", "#1ca9c4")
            $("#staticBackdrop").modal("show");
        }else {
            let mManufacture ={"designer": $("#designer").val(),"remark":$("#remark").val()};
            localStorage.setItem("MMADD_mManufacture",JSON.stringify(mManufacture));
            localStorage.setItem("MMADD(2)",JSON.stringify(duixiang));
            location.href="../../wen_zhi_yi/mManufactureAdd(2).html";
        }
    })
}